package com.usian.store.controller;

import com.github.pagehelper.PageInfo;
import com.usian.common.pojo.Dept;
import com.usian.common.pojo.UserStore;
import com.usian.common.vo.ResultVo;
import com.usian.common.vo.WmsVo;
import com.usian.store.fegin.DeptFegin;
import com.usian.store.service.UserStoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @TODO:
 * @Author:baimu
 * @Date:2024 07 02 09 00
 **/
@RequestMapping("/api/user-store")
@RestController
@Slf4j
public class UserStoreController {

   @Autowired
   UserStoreService userStoreService;

   @PostMapping("/login")
    public ResultVo login(@RequestBody UserStore userStore) {
        ResultVo resultVo = userStoreService.selectByUsername(userStore);
        return resultVo;

    }


    @PostMapping("/reg")
    public ResultVo reg(@RequestBody UserStore userStore){
       return userStoreService.saveUserStore(userStore);
    }

   @Autowired
   DeptFegin deptFegin;

   @GetMapping("/findAllDept")
    public ResultVo findAllDept(){
        List<Dept> all = deptFegin.findAll();
        return ResultVo.ok(all);
    }


    @PostMapping("/updateUserStore")
    public ResultVo updateUserStoreByName(@RequestBody UserStore userStore){
       return userStoreService.updateUserStore(userStore);
    }
    @PostMapping("/updateUserStoreById")
    public ResultVo updateUserStoreById(@RequestBody UserStore userStore){
        return userStoreService.updateUserStoreById(userStore);
    }




    @RequestMapping("/findAll")
    public ResultVo findAll( WmsVo vo){
       log.info("前台传过来的WmsVo：{}",vo.toString());
        PageInfo pageInfo = userStoreService.findAll(vo);
        return ResultVo.ok(pageInfo);
    }

//    @RequestMapping("/findAll")
//    public ResultVo findAll1( @RequestParam Integer deptId,String keyword, Integer pageNumber,Integer pageSize){
//        PageInfo pageInfo = userStoreService.findAll(vo);
//        return ResultVo.ok(pageInfo);
//    }


    @GetMapping("/deleteUserStoreById/{id}")
    public ResultVo deleteUserStoreById(@PathVariable Integer id){
       return userStoreService.deleteUserStoreById(id);

    }


}
